/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.crud.patient.patientComponents.sugeries;

import java.util.ArrayList;
import org.jdesktop.swingx.JXTable;
import systole.domain.clinicalInformation.SurgeryPatient;
import systole.domain.persons.Patient;
import systole.exceptions.ExceptionDAO;

import systole.view.crud.patient.patientComponents.controller.ControllerViewPatientComponent;
import systole.view.crud.tableModels.SurgeriesByPatientTableModel;

/**
 *
 * @author jmj
 */
public class ControllerViewSurgeryByPatient extends ControllerViewPatientComponent {

    /**
     * @param table
     * @param patient
     * @param editing
     * @throws ExceptionDAO
     */
    public ControllerViewSurgeryByPatient(JXTable table, Patient patient, boolean editing){
        super(table, patient, editing);
        this.entityList = new ArrayList(this.patient.getSurgeriesPatient());
        this.tableModel = new SurgeriesByPatientTableModel(this.entityList);
        this.table.setModel(this.tableModel);
        this.controllerEntityEdition = new ControllerEditionSugeryByPatient(patient);
    }

    @Override
    protected void deleteEntity(Object entity) {
        this.patient.getSurgeriesPatient().remove((SurgeryPatient) entity);
    }

    @Override
    protected void refreshList() {
        this.entityList = new ArrayList(this.patient.getSurgeriesPatient());
        this.tableModel.refreshList(this.entityList);
        this.table.setModel(this.tableModel);
        this.table.revalidate();
    }
}
